#include "../base/worker_mgr.h"
#include "../base/sche_mgr.h"
#include "../base/sche.h"

#include "../base/task.h"
#include "../base/th.h"

#include <assert.h>
#include <stdio.h>


static int i = 0;

static void* _main( void* par ) {
	/*
	printf("current_thread:%d\n",thread_current());
	printf("index : %d\n" , *(int*)(par) );
	*/
	++i;
	return NULL;
}

static void _clean( void* par , void* r ) {
}



void test1() {
	/*
	 * Testing the fix scheduler and also the worker manager as well as the dbworker 
	 */
	 struct sche_mgr * smgr = sche_mgr_create();
	 struct worker_mgr* wmgr = worker_mgr_create();
	 struct sche* fs = sche_mgr_spawn_sche(smgr,"fixsche","holicworker",wmgr,8);
	 size_t i ;
	 struct task t;
	 worker_mgr_destroy(wmgr);
	 sche_mgr_destroy(smgr);
	 
	 for( i = 0 ; i < 500000 ; ++i ) {
		 t.work = _main;
		 t.clean= _clean;
		 t.par = &i;
		 fs->dispatch(fs,&t);
	 }
	 
	 fs->signal_quit(fs,false,NULL);
	 assert( i == 500000 );
}


void test() {
	test1();
}
